﻿﻿﻿@extends('admin.Default')
@section('type')
    <link href="{{ asset('myadmin/css/plugins/dataTables/dataTables.bootstrap.css') }}" rel="stylesheet">
@stop
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户信息： <small>所有用户信息</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr >
                                <th >用户编号</th>
                                <th >用户头像</th>
                                <th >用户名</th>
                                <th >用户昵称</th>
                                <th >用户真实姓名</th>
                                <th >用户性别</th>
                                <th >用户年龄</th>
                                <th >用户手机</th>
                                <th >用户积分</th>
                                <th >用户状态</th>
                                <th >&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($list as $v)
                                <tr align="center">
                                    <td>{{$v->user_id}}</td>
                                    <td><img src="@if(strstr($v->photo,"http://wx.qlogo.cn")) {{ $v->photo }} @else {{ url('upload/user/'.$v->photo) }} @endif" width="30"height="30" alt="无"></td>
                                    <td>{{$v->username}}</td>
                                    <td>{{$v->nickname}}</td>
                                    <td>{{$v->name}}</td>
                                    <td>{{$v->sex == 'm'?'男':'女'}}</td>
                                    <td>{{$v->age}}</td>
                                    <td>{{$v->phone}}</td>
                                    <td>{{$v->integral}}</td>
                                    <td>
                                        @if ($v->status == 1)
                                            <a onclick="doDel({{ $v->user_id }},{{ $v->status }}, this)" id="z" >正常</a>
                                        @else
                                            <a onclick="doDel({{ $v->user_id }},{{ $v->status }}, this)"  id="d" >冻结</a>
                                        @endif
                                    </td>
                                    <td>
                                        <a href="{{ url('admin/user/userlist/'.$v->user_id.'/edit') }}">修改</a> |
                                        <a onclick="doaddress({{ $v->user_id }},'{{ $v->username }}');" data-toggle="modal" class="" href="#modal-form-one"  >收货地址</a>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>

    <div id="modal-form-one" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-6">
                            <div class="ibox float-e-margins">
                                <div class="ibox-title">
                                    <h5 id="address"></h5>
                                    <div class="ibox-tools">
                                        <a class="collapse-link">
                                            <i class="fa fa-chevron-up"></i>
                                        </a>

                                    </div>
                                </div>
                                <div class="ibox-content ">

                                    <table class="table table-bordered address">
                                        <thead>
                                        <tr>
                                            <th >地址编号</th>
                                            <th >收货人姓名</th>
                                            <th >收货人手机号</th>
                                            <th >省份与城市</th>
                                            <th >详细地址</th>
                                            <th >地址使用状态</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mainly scripts -->
@stop
@section('script')
    <script type="text/javascript" src="{{ asset('myadmin/js/jquery.min.js') }}"></script><script type="text/javascript"  src="{{ asset('myadmin/js/jquery-2.1.1.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/bootstrap.min.js?v=3.4.0') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/metisMenu/jquery.metisMenu.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/slimscroll/jquery.slimscroll.min.js') }}"></script>
    <!-- iCheck -->
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/iCheck/icheck.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>

    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/jeditable/jquery.jeditable.js') }}"></script>

    <!-- Data Tables -->
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dataTables/jquery.dataTables.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dataTables/dataTables.bootstrap.js') }}"></script>
    <script type="text/javascript">
        function doDel(id,status, bn){

            if(confirm("你确定要这样做吗？")){
                $.ajax({
                    url:'{{ url("admin/user/ajax/status") }}',
                    async:false,				//是否异步
                    type:'post',				//请求方式
                    data:{id:id, status:status,  '_token': $('input[name=_token]').val()},				//发送的数据
                    dataType:'json',			//响应的数据类型
                    success:function(data)		//成功时回调函数
                    {
                        if(data == '1'){
                            $(bn).parent().append('<a onclick="doDel('+id+',1, this)" >正常</a>');
                            $(bn).remove();
                        }else{
                            $(bn).parent().append('<a onclick="doDel('+id+',2, this)" >冻结</a>');
                            $(bn).remove();
                        }
                    }
                });
            }
        }

        function doaddress(id, username)
        {
            $('.address tbody').children().remove();
            $.ajax({
                url:'{{ url("admin/user/ajax/seladdress") }}',
                async:false,				//是否异步
                type:'post',				//请求方式
                data:{id:id, status:status,  '_token': $('input[name=_token]').val()},				//发送的数据
                dataType:'json',			//响应的数据类型
                success:function(data)		//成功时回调函数
                {
                    if(data == null){
                        $('.address').css('display','none');
                        $('#address').html('用户：'+ username +' 还没有设置收货地址');
                    }else{
                        $('.address').css('display','');
                        $('#address').html('用户：'+ username +' 的收货地址如下');
                        for (var i = 0; i < data.length; i++) {
                            var status = data[i].status == 1 ? '未使用':'使用中';
                            $('.address tbody').append("<tr><td>"+data[i].id+"</td><td>"+data[i].name+"</td><td>"+data[i].phone+"</td><td>"+data[i].city+"</td><td>"+data[i].detail+"</td><td>"+status+"</td></tr>");
                        };
                    }
                }
            });
        }


        function docart(id, username)
        {
            {{--$.ajax({--}}
                {{--url:'{{ url("admin/user/ajax/seladdress") }}',--}}
                {{--async:false,				//是否异步--}}
                {{--type:'post',				//请求方式--}}
                {{--data:{id:id, status:status,  '_token': $('input[name=_token]').val()},				//发送的数据--}}
                {{--dataType:'json',			//响应的数据类型--}}
                {{--success:function(data)		//成功时回调函数--}}
                {{--{--}}
                    {{--if(data == null){--}}
                        {{--$('.address').css('display','none');--}}
                        {{--$('#address').html('用户：'+ username +' 还没有设置收货地址');--}}
                    {{--}else{--}}
                        {{--$('.address').css('display','');--}}
                        {{--$('#address').html('用户：'+ username +' 的收货地址如下');--}}
                        {{--for (var i = 0; i < data.length; i++) {--}}
                            {{--var status = data[i].status == 1 ? '未使用':'使用中';--}}
                            {{--$('.address tbody').append("<tr><td>"+data[i].id+"</td><td>"+data[i].name+"</td><td>"+data[i].phone+"</td><td>"+data[i].city+"</td><td>"+data[i].detail+"</td><td>"+status+"</td></tr>");--}}
                        {{--};--}}
                    {{--}--}}
                {{--}--}}
            {{--});--}}
        }




        $(document).ready(function () {
            $('.dataTables-example').dataTable();
            var oTable = $('#editable').dataTable();
            oTable.$('td').editable('../example_ajax.php', {
                "callback": function (sValue, y) {
                    var aPos = oTable.fnGetPosition(this);
                    oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                },
                "submitdata": function (value, settings) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition(this)[2]
                    };
                },
                "width": "90%",
                "height": "100%"
            });
        });
    </script>

@stop